package com.apartment.own.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnOrdPaymentTier;
import com.apartment.own.service.IOwnOrdPaymentTierService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

/**
 * 付款分阶Controller
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/tier")
public class OwnOrdPaymentTierController extends BaseController
{
    @Autowired
    private IOwnOrdPaymentTierService ownOrdPaymentTierService;

    /**
     * 查询付款分阶列表
     */
    @PreAuthorize("@ss.hasPermi('own:tier:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnOrdPaymentTier ownOrdPaymentTier)
    {
        startPage();
        List<OwnOrdPaymentTier> list = ownOrdPaymentTierService.selectOwnOrdPaymentTierList(ownOrdPaymentTier);
        return getDataTable(list);
    }

    /**
     * 导出付款分阶列表
     */
    @PreAuthorize("@ss.hasPermi('own:tier:export')")
    @Log(title = "付款分阶", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnOrdPaymentTier ownOrdPaymentTier)
    {
        List<OwnOrdPaymentTier> list = ownOrdPaymentTierService.selectOwnOrdPaymentTierList(ownOrdPaymentTier);
        ExcelUtil<OwnOrdPaymentTier> util = new ExcelUtil<OwnOrdPaymentTier>(OwnOrdPaymentTier.class);
        return util.exportExcel(list, "tier");
    }

    /**
     * 获取付款分阶详细信息
     */
    @PreAuthorize("@ss.hasPermi('own:tier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ownOrdPaymentTierService.selectOwnOrdPaymentTierById(id));
    }

    /**
     * 新增付款分阶
     */
    @PreAuthorize("@ss.hasPermi('own:tier:add')")
    @Log(title = "付款分阶", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnOrdPaymentTier ownOrdPaymentTier)
    {
        return toAjax(ownOrdPaymentTierService.insertOwnOrdPaymentTier(ownOrdPaymentTier));
    }

    /**
     * 修改付款分阶
     */
    @PreAuthorize("@ss.hasPermi('own:tier:edit')")
    @Log(title = "付款分阶", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnOrdPaymentTier ownOrdPaymentTier)
    {
        return toAjax(ownOrdPaymentTierService.updateOwnOrdPaymentTier(ownOrdPaymentTier));
    }

    /**
     * 删除付款分阶
     */
    @PreAuthorize("@ss.hasPermi('own:tier:remove')")
    @Log(title = "付款分阶", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ownOrdPaymentTierService.deleteOwnOrdPaymentTierByIds(ids));
    }
}
